package com.caption.controller;

import com.caption.api.entity.FaceAuthCondition;
import com.caption.api.entity.FaceAuthResultDTO;
import com.caption.api.entity.IDCarAuthCondition;
import com.caption.api.entity.IDCarAuthResultDTO;
import com.caption.api.handler.manager.ApiHandlerManager;
import com.caption.core.handler.DispatcherManager;
import com.caption.core.result.TCRequest;
import com.caption.core.result.TCResponse;
import com.caption.entity.TransactionDo;
import com.caption.entity.UserInfo;
import com.caption.service.TransactionService;
import com.caption.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private ApiHandlerManager apiHandlerManager;

    @Autowired
    private DispatcherManager dispatcherManager;
    @Autowired
    private TransactionService transactionService;

    @GetMapping(value = "/info/{id}")
    public UserInfo getUserInfo(@PathVariable("id") Integer id) {
        return userService.getInfoById(id);
    }


    /**
     * 异步处理
     *
     * @return
     */
    @PostMapping(value = "/sync/info")
    public TCResponse getInfo(@RequestBody TCRequest tcRequest) {
        return dispatcherManager.handle(tcRequest);
    }


    @GetMapping(value = "/api/idCard")
    public IDCarAuthResultDTO getApiIdCard() throws Exception {
        apiHandlerManager.setHandler(new IDCarAuthCondition(), "v1.0");
        IDCarAuthResultDTO idCarAuthResultDTO = apiHandlerManager.call();
        return idCarAuthResultDTO;
    }

    @GetMapping(value = "/api/face")
    public FaceAuthResultDTO getApiFace() throws Exception {
        apiHandlerManager.setHandler(new FaceAuthCondition(), "v1.0");
        FaceAuthResultDTO faceAuthResultDTO = apiHandlerManager.call();
        return faceAuthResultDTO;
    }
}
